package com.tyk.bookstore.back.member.service.impl;


import com.tyk.bookstore.back.common.core.util.AssertUtil;
import com.tyk.bookstore.back.member.model.dto.DeliveryAddress4OrderDto;
import com.tyk.bookstore.back.member.model.dto.MemberAddress4WaybillDto;
import com.tyk.bookstore.back.member.model.entity.DeliveryAddressDo;
import com.tyk.bookstore.back.member.model.result.DeliveryAddressResultEnum;
import com.tyk.bookstore.back.member.repository.DeliveryAddressRepository;
import com.tyk.bookstore.back.member.service.DeliveryAddressApiService;
import com.tyk.bookstore.back.member.util.MapStructMember;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class DeliveryAddressApiServiceImpl implements DeliveryAddressApiService {
    private final DeliveryAddressRepository deliveryAddressRepository;
    private final MapStructMember mapStructMember;


    @Override
    public String getAddressById(Long id) {
        return deliveryAddressRepository.selectAddressById(id);
    }

    @Override
    public DeliveryAddress4OrderDto getDeliveryAddressById(Long id) {
        DeliveryAddressDo deliveryAddress = deliveryAddressRepository.selectById(id);
        return mapStructMember.toDeliveryAddress4OrderDto(deliveryAddress);
    }

    @Override
    public MemberAddress4WaybillDto getMemberAddress4WaybillDtoById(Long id) {
        MemberAddress4WaybillDto dto = deliveryAddressRepository.selectMemberAddress4WaybillDtoById(id);
        AssertUtil.notNull(dto, DeliveryAddressResultEnum.ADDRESS_NOT_FOUND);
        return dto;
    }
}
